/*
 * queryGuestRoomState.java
 *
 * Created on __DATE__, __TIME__
 */

package hotel.view;

import hotel.dao.BianJiDao;
import hotel.util.DbUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import javax.swing.ImageIcon;

public class queryGuestRoomState extends javax.swing.JInternalFrame {

	DbUtil dbUtil = new DbUtil();
	BianJiDao editModulDao = new BianJiDao();
	public queryGuestRoomState() {
		initComponents();
		String roomNum = null;
		this.fillTable(roomNum);
		this.setLocation(200, 50);//设置窗口位置
	}

	public void fillTable(String roomNum) {
		DefaultTableModel dtm = (DefaultTableModel) guestRoomInfoTable
				.getModel();
		dtm.setRowCount(0);
		Connection con = null;
		try {
			con = dbUtil.getCon();
			ResultSet re = editModulDao.findGuestRoomState(con, roomNum);
			while (re.next()) {
				Vector v = new Vector();
				//添加每一行的数据
				v.add(re.getString("id"));
				v.add(re.getString("num"));
				String state = re.getString("state");
				if (state.equals("0")) {
					state = "未入住";
				} else {
					state = "入住中";
				}
				v.add(state);
				dtm.addRow(v);
			}
		} catch (Exception e) {
			
			e.printStackTrace();
		} finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
			
				e.printStackTrace();
			}
		}
	}

	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();

		jLabel1.setFont(new Font("宋体", Font.PLAIN, 22));
		roomNum = new javax.swing.JTextField();
		search = new javax.swing.JButton();
	
		search.setFont(new Font("宋体", Font.PLAIN, 22));
		jScrollPane1 = new javax.swing.JScrollPane();
		guestRoomInfoTable = new javax.swing.JTable();

		setClosable(true);
		setIconifiable(true);
		setTitle("查询客房状态");

		jLabel1.setText("房间号");

		search.setText("查询");
		search.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				searchActionPerformed(evt);
			}
		});

		guestRoomInfoTable.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null }, { null, null, null },
						{ null, null, null }, { null, null, null } },
				new String[] { "编号", "房间号", "状态" }) {
			boolean[] canEdit = new boolean[] { false, false, false };

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		jScrollPane1.setViewportView(guestRoomInfoTable);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				layout.createSequentialGroup().add(28, 28, 28).add(jLabel1)
						.add(18, 18, 18).add(roomNum,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								138,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.add(32, 32, 32).add(search).addContainerGap(236,
								Short.MAX_VALUE)).add(
				layout.createSequentialGroup().addContainerGap().add(
						jScrollPane1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 533,
						Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				layout.createSequentialGroup().add(29, 29, 29).add(
						layout.createParallelGroup(
								org.jdesktop.layout.GroupLayout.BASELINE).add(
								jLabel1).add(roomNum,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(search)).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(
						jScrollPane1,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 229,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(49, Short.MAX_VALUE)));

		pack();
	}
	private void searchActionPerformed(java.awt.event.ActionEvent evt) {
		String roomNum = this.roomNum.getText();
		this.fillTable(roomNum);
	}

	
	private javax.swing.JTable guestRoomInfoTable;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextField roomNum;
	private javax.swing.JButton search;


}